package com.petRescueCenter.demo.posting.entity;

import java.util.Date;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.petRescueCenter.demo.common.enumPackage.LockedEmun;
import com.petRescueCenter.demo.common.enumPackage.pTypeEmun;
import com.petRescueCenter.demo.img.entity.Img;
import com.petRescueCenter.demo.user.entity.User;

@Entity
@Table(name = "t_posting")
public class Posting {
	private Long id;
	private Set<Img> imgs;
	private String content;
	private Date createTime;
	private String title;
	private pTypeEmun type;
	private User author;
	private Set<Reply> replys;
	private Set<User> fans;
	private LockedEmun state;

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getContent() {
		return content;
	}

	@Temporal(TemporalType.TIMESTAMP)
	@JsonFormat(pattern = "yyyy/MM/dd HH:mm:ss", timezone = "GMT+8")
	public Date getCreateTime() {
		return createTime;
	}

	public String getTitle() {
		return title;
	}

	public pTypeEmun getType() {
		return type;
	}

	public LockedEmun getState() {
		return state;
	}

	public void setState(LockedEmun state) {
		this.state = state;
	}

	@OneToMany(cascade = { CascadeType.ALL }, fetch = FetchType.LAZY)
	@JoinColumn(name = "postingId")
	public Set<Img> getImgs() {
		return imgs;
	}

	@ManyToOne
	@JoinColumn(name = "userId")
	public User getAuthor() {
		return author;
	}

	@OneToMany
	@JoinColumn(name = "postingId")
	public Set<Reply> getReplys() {
		return replys;
	}

	@ManyToMany(mappedBy = "attentions")
	public Set<User> getFans() {
		return fans;
	}

	public void setReplys(Set<Reply> replys) {
		this.replys = replys;
	}

	public void setFans(Set<User> fans) {
		this.fans = fans;
	}

	public void setAuthor(User author) {
		this.author = author;
	}

	public void setImgs(Set<Img> imgs) {
		this.imgs = imgs;
	}

	public void setContent(String content) {
		this.content = content;
	}

	@Temporal(TemporalType.TIMESTAMP)
	@JsonFormat(pattern = "yyyy/MM/dd HH:mm:ss", timezone = "GMT+8")
	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public void setType(pTypeEmun type) {
		this.type = type;
	}

	@Override
	public String toString() {
		return "Posting [id=" + id + ", imgs=" + imgs + ", content=" + content + ", createTime=" + createTime
				+ ", title=" + title + ", type=" + type + ", author=" + author + ", replys=" + replys + ", fans=" + fans
				+ "]";
	}

}
